package com.skit.main.data

import android.util.ArrayMap
import com.skit.common.bean.ActivityBean
import com.skit.common.http.NetResult
import com.skit.common.ktx.RetrofitKtx.getService
import com.skit.common.ktx.init
import com.skit.common.retrofit.ActivityProtocol
import retrofit2.Retrofit
import javax.inject.Inject

class HomeActivityRepository @Inject constructor(private val retrofit: Retrofit) {

    private var page: Int = 1

    suspend fun getActivity(limit: Int, skip: Int, type: Int): NetResult<List<ActivityBean>> {
        val map: ArrayMap<String, Any> = ArrayMap()
        map["page"] = page
        map["limit"] = limit
        map["skip"] = skip
        map["type"] = type
        val service = retrofit.getService(ActivityProtocol::class.java)
        val data = service.getActivityListSync(limit, skip, type)
        return data.init().apply {
            if (this is NetResult.Success) page += 1
        }
    }

    suspend fun getUserCollectActivityList(
        refresh: Boolean,
        uid: Int,
    ): NetResult<List<ActivityBean>> {
        if (refresh) page = 1
        val map: ArrayMap<String, Any> = ArrayMap()
        map["page"] = page
        map["uid"] = uid
        val service = retrofit.getService(ActivityProtocol::class.java)
        val data = service.getUserCollectActivityList(uid, page)
        return data.init().apply {
            if (this is NetResult.Success) page += 1
        }
    }
}